<template>
  <div class="formplane">
    <el-form ref="elForm" :model="formdata" size="medium" :rules="rules" label-width="100px">
      <el-form-item label="驳回节点" prop="nodeno" label-width="100px" v-if="isshow">
        <el-select v-model="nodeno" placeholder="请选择驳回节点">
          <el-option v-for="item in nodes" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="驳回意见" prop="commentContent" label-width="100px">
        <el-input type="textarea" :rows="2" placeholder="请输入驳回意见" v-model="formdata.commentContent" maxlength="1000">
        </el-input>
      </el-form-item>
      <el-form-item label-width="100px" class="buttonitem">
        <el-button type="primary" @click="confirm">确定</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  props: ['nodelist'],
  data () {
    return {
      formdata: { commentContent: '' },
      nodeno: '',
      nodename: '',
      nodes: this.nodelist,
      isshow: true,
      rules: {
        commentContent: [
          {
            required: true,
            message: '沟通意见必填',
            trigger: 'blur'
          }
        ],
        nodeno: [
          {
            required: true,
            message: '驳回节点必填',
            trigger: 'blur'
          }
        ]
      }
    }
  },
  created () {
    if (this.nodelist !== undefined && this.nodelist.length === 1) {
      this.nodeno = this.nodelist[0].nodeno
      this.nodename = this.nodelist[1].nodename
      this.isshow = false
    }
  },
  methods: {
    cancel () {
      this.$emit('cancel')
    },
    confirm () {
      this.$refs.elForm.validate(valid => {
        if (!valid) return
        this.$emit('confirm', {
          nodeno: this.nodeno,
          nodename: this.nodename,
          ApprovedDes: this.formdata.commentContent
        })
      })
    }
  }
}
</script>
<style scoped>
.formplane {
  margin: 15px;
}
.buttonitem >>> .el-form-item__content {
  float: right;
  height: 100%;
}
</style>
